﻿using System.Web.Mvc;
using ClassLibrary1.Services;

namespace ClassLibrary1
{
    public class ClientModelBinder : DefaultModelBinder
    {
        protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, System.Type modelType)
        {
            var value = bindingContext.ValueProvider.GetValue("id");
            if (value == null) return ClientService.New();
            var result = (int)value.ConvertTo(typeof(int));
            return ClientService.GetById(result);
        }
    }
}
